<?php
include('function/connection.php'); 
if(isset($_GET['from_sales_purchase_date']) && isset($_GET['to_sales_purchase_date']) && $_GET['from_sales_purchase_date']!='' && $_GET['to_sales_purchase_date']!='' )
{ 
	error_reporting (E_ALL ^ E_NOTICE);
			$selected_date=$_GET['from_sales_purchase_date'];
		  	$selected_date=strtotime( $selected_date );
			$mysqldate = date( 'Y-m-d H:i:s', $selected_date );
$fromdate=$mysqldate;
			$selected_date=$_GET['to_sales_purchase_date'];
		  	$selected_date=strtotime( $selected_date );
			$mysqldate = date( 'Y-m-d H:i:s', $selected_date );

$todate=$mysqldate;
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Purchase Report</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<style type="text/css" media="print">
.hide{display:none}
</style>
<script type="text/javascript">
function printpage() {
document.getElementById('printButton').style.visibility="hidden";
window.print();
document.getElementById('printButton').style.visibility="visible";  
}
</script>
<body style="font-size:13px;">
<input name="print" type="button" value="Print" id="printButton" onClick="printpage()">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td align="center">
      <table width="800" border="0" cellspacing="0" cellpadding="0">
       
        <tr>
          <td height="30" align="left"><h3><img src="images/logo_marly.png" width="130"  height="40" />&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Stock Purchase Report </h3> </strong></td>
          <td width="35%"><strong>Hay Soeung Company</strong><br />
Russian Blvd Sang Kat Toek Thla, <br />Khan Sen Sok, Phnom Penh, Cambodia<br />
Email: hay_soeng@yahoo.com<br/>
Website:&nbsp;www.haysoeungautomobile.com<br />
Tel: <span large;\>+85512 544498</span><br />&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;+85512 287899<br/>
			
		  </td>
        </tr>
        <tr>
          <td height="30" align="center" colspan="2">&nbsp;</td>
        </tr>
        <tr>
          <td align="center"><table width="100%" border="0" cellspacing="0" cellpadding="0">
            <tr>
              <td align="left" colspan="2"><table width="300" border="0" cellspacing="0" cellpadding="0">
                <tr>
                  <td width="150"><strong>Total Purchase</strong></td>
                  <td width="150">&nbsp;<?php 
				$sql="SELECT sum(amount) as total_amount FROM tbl_stocks WHERE count=1 AND type='entry' AND pd_date BETWEEN '$fromdate' AND '$todate'";
				$result=mysql_query($sql);
				$row=mysql_fetch_assoc($result);
				echo $row['total_amount']."$";
			  ?></td>
                </tr>
                <tr>
                  <td><strong>Paid Amount</strong></td>
                  <td><?php 
			  	$sql="SELECT sum(paid) as total_paid FROM tbl_stocks WHERE count=1 AND type='entry' AND pd_date BETWEEN '$fromdate' AND '$todate'";
				$result=mysql_query($sql);
				$row=mysql_fetch_assoc($result);
				echo $row['total_paid']."$";
			?></td>
                </tr>
                <tr>
                  <td width="150"><strong>Pending Payment </strong></td>
                  <td width="150">&nbsp;<?php 
				$sql="SELECT sum(balance) as balance FROM tbl_stocks WHERE count=1 AND type='entry' AND pd_date BETWEEN '$fromdate' AND '$todate'";
				$result=mysql_query($sql);
				$row=mysql_fetch_assoc($result);
				echo $row['balance']."$";
			  ?></td>
                </tr>
              </table></td>
              <td align="right">&nbsp;</td>
            </tr>
          </table></td>
        </tr>
        <tr>
          <td width="45" colspan="2"><hr></td>
        </tr>
        <tr>
          <td height="20" colspan="2"><table width="100%"  border="0" cellspacing="0" cellpadding="0">
              <tr>
                <td width="45"><strong>From</strong></td>
                <td width="393">&nbsp;<?php echo $_GET['from_sales_purchase_date']; ?></td>
                <td width="41"><strong>To</strong></td>
                <td width="116">&nbsp;<?php echo $_GET['to_sales_purchase_date']; ?></td>
              </tr>
          </table></td>
        </tr>
        <tr>
          <td width="45" colspan="2"><hr></td>
        </tr>
        <tr>
          <td colspan="2">
              <table width="100%"  border="0" cellspacing="0" cellpadding="0">
                  <tr>
                    <td width="5%"><strong>No</strong></td>
                    <td width="15%"><strong>Date</strong></td>
                    <td width="10%"><strong>Supplier<br>
                    </strong></td>
                    <td width="30%" align="center"><strong>Product</strong></td>
                    <td width="8%" align="center"><strong>Quantity</strong></td>
                    <td width="15%" align="center"><strong>Buying<br> Price</strong></td>
                    <td width="15%" align="center"><strong>Selling <br>Price</strong></td>
                    <td width="15%" align="left"><strong>Opening<br>
                    Stock</strong></td>
                    <td width="15%" align="left"> <strong>Closing<br>
                      Stock</strong></td>
                    <td width="10%" align="right"><strong>Total</strong></td>
                  </tr>
                  <tr>
                    <td>&nbsp;</td>
                    <td>&nbsp;</td>
                    <td>&nbsp;</td>
                    <td>&nbsp;</td>
                    <td>&nbsp;</td>
                    <td>&nbsp;</td>
                    <td>&nbsp;</td>
                    <td>&nbsp;</td>
                    <td>&nbsp;</td>
                    <td>&nbsp;</td>
                  </tr>
                  <?php  
                    $sql="SELECT * FROM tbl_stocks where type='entry' AND pd_date BETWEEN '$fromdate' AND '$todate' ORDER BY pd_date DESC ";
                    $result=mysql_query($sql);
                    $j=1;
                    while ($line = mysql_fetch_object($result)) {
                ?>
                
                    <tr>
                    <td width="5%"><?php echo "00".$j;?></td>
                    <td align="left"><?php  $mysqldate=$line->pd_date;
            $phpdate = strtotime( $mysqldate );
            $phpdate = date("d/m/Y",$phpdate);
            echo $phpdate; ?></td>
                    <td><?php echo $line->sup_name; ?></td>
                    <td><?php echo $line->pd_name; ?></td>
                    <td align="center"><?php echo $line->qty;  ?></td>
                    <td align="center"><?php echo $line->buying_price."$";  ?></td>
                    <td align="center"><?php echo $line->selling_price."$";  ?></td>
                    <td align="center"><?php echo $line->opening_stock; ?></td>
                    <td align="center"><?php echo $line->closing_stock; ?></td>
                    <td align="right" width="15%"><?php echo $line->total."$";?></td>
                  </tr>
                    
    
                <?php
                    $j++;
                    }
                 ?>
              </table>
       </td>
        </tr>
        <tr>
          <td colspan="2">&nbsp;</td>
        </tr>
        <tr>
          <td colspan="2">&nbsp;</td>
        </tr>
    </table></td>
  </tr>
</table>

</body>
</html>
<?php
}
else{
echo "Please from and to date to process report";
}
?>